"""
@Author: Eobard Gu
@Date: 2025-07-31
@Description: 更改mp3文件md5哈希值
    使用该脚本需要安装依赖和FFmpeg
        pip3 install pydub 
    安装以来的音频处理工具(macOS)
        brew install  ffmpeg
"""
import sys
from pydub import AudioSegment
import os

def main():
    if len(sys.argv)<3:
        print("python脚本执行失败：音频源路径或音频保存路径不能为空")
        sys.exit(1)
    
    raw_path=sys.argv[1]
    target_path=sys.argv[2]

    if not raw_path.strip() or not target_path.strip():
        print("python脚本执行失败：音频源路径或音频保存路径不能为空")
        sys.exit(1)

    if not os.path.exists(target_path):
        os.makedirs(target_path)

    # 处理音频
    print("开始处理音频...")
    for mp3_name in os.listdir(raw_path):
        if mp3_name.endswith("mp3"):
            mp3_abs_path = os.path.join(raw_path, mp3_name)
            music = AudioSegment.from_mp3(file=mp3_abs_path)
            save_file_path = os.path.join(target_path, mp3_name)
            music.export(out_f=save_file_path, format='mp3')
        pass
    print(f"{raw_path}:音频md5更改成功")

if __name__ == "__main__":
    main()      